Skip to content

Conversation

arthurlw
Copy link
Member

@arthurlw arthurlw commented Sep 2, 2025

@arthurlw arthurlw changed the title Updated _infer_matches and _maybe_downcast_for_indexing DEPR: Remove special date case from _maybe_downcast_for_indexing Sep 5, 2025
@arthurlw arthurlw changed the title DEPR: Remove special date case from _maybe_downcast_for_indexing DEPR: Remove special date-datetime64 case in indexing Sep 5, 2025
x, "M"
) or isinstance(x, DatetimeTZDtype)
_infer_matches = ("datetime", "datetime64", "date")
_infer_matches = ("datetime", "datetime64")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be worth doing, but the motivating issue I opened was only about the check in indexes.base

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my testing after removing the check in indexes.base, the example in the original issue still fails because of _infer_matches called under _validate_listlike

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looking at the other places where _infer_matches is used, im OK with that change, but will need to make sure we have appropriate testing and whatsnew note for e.g. equals

result2 = target.get_indexer(index)
tm.assert_numpy_array_equal(result2, expected)

def test_get_indexer_date_objs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of removing the test entirely, test the new behavior, with a comment about the history/change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(havent looked closely, but this likely applies to tests below)

@arthurlw arthurlw marked this pull request as ready for review September 14, 2025 19:32
ts_slice = ts[5:]
ts2 = ts_slice.copy()
ts2.index = [x.date() for x in ts2.index]
ts2.index = pd.to_datetime([x.date() for x in ts2.index])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of this, test the new behavior with the old index

def test_categorical_coerces_timestamp(all_parsers):
parser = all_parsers
dtype = {"b": CategoricalDtype([Timestamp("2014")])}
dtype = {"b": CategoricalDtype([Timestamp("2014-01-01 12:00:00")])}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when read_csv reads "b\n2014-01-01\n2014-01-01" it converts the data into date objects, while the Timestamps are in datetime64. With the deprecation in this PR, this is no longer supported. Updating the data with the time "b\n2014-01-01 12:00:00\n2014-01-01 12:00:00"ensures read_csv produces datetime64 values that match the Timestamp categories

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we want to continue testing the original input data


def test_categorical_coerces_datetime(all_parsers):
parser = all_parsers
dti = pd.DatetimeIndex(["2017-01-01", "2018-01-01", "2019-01-01"], freq=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?

@jbrockmendel
Copy link
Member

this looks almost ready. can you address comments and get the code checks CI passing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: indexing dates-with-datetime64

2 participants